//
//  XMMeetSearchViewController.m
//  XMJJ_zmy
//
//  Created by 丁浩 on 2025/7/10.
//

#import "XMMeetSearchViewController.h"
#import "XMMeetSearchView.h"
#import "XMNetwork+home.h"
#import "XMNetwork+mine.h"
#import "ZMYCommend.h"
#import "XMHAreaModel.h"

#import "XMMeetDetailViewController.h"

@interface XMMeetSearchViewController () <XMMeetSearchViewDelegate>

@property (nonatomic, strong) XMMeetSearchView *meetSearchView;

@property (nonatomic, assign) int page;

@end

@implementation XMMeetSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.meetSearchView];
    _page = 1;
    [self getAreaInfo];
}

- (void)meetSearchWithSearchKey:(NSString *)searchKey
                    isAscending:(NSString *)isAscending
                           city:(NSString *)city {
    XMWeakSelf;
    [_Network meetSearchWithSearchKey:searchKey
                          isAscending:isAscending
                                 city:city
                                 page:[NSString stringWithFormat:@"%d", _page]
                              success:^(id  _Nonnull responseObject) {
        NSArray *productModelArr = [NSArray yy_modelArrayWithClass:[ZMYCommend class] json:[responseObject safeArrayForKey:@"data"]];
        [weakSelf.meetSearchView setContentWithProductModelArr:productModelArr
                                                          page:weakSelf.page];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

- (void)getAreaInfo {
    XMWeakSelf;
    [_Network getAreaListSuccess:^(id  _Nonnull responseObject) {
        NSArray *areaModelArr = [NSArray yy_modelArrayWithClass:[XMHAreaModel class] json:responseObject[@"data"]];
        [weakSelf.meetSearchView setAreaSelectInfoWithAreamodelArr:areaModelArr];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

#pragma mark - Delegate
- (void)checkDetailWithProdId:(NSString *)prodId {
    XMMeetDetailViewController * detailVC = [XMMeetDetailViewController new];
    detailVC.hidesBottomBarWhenPushed = YES;
    detailVC.serviceId = prodId;
    [self.navigationController pushViewController:detailVC animated:YES];
}

- (void)areaSelectAction {
    [self getAreaInfo];
}

- (XMMeetSearchView *)meetSearchView {
    if (!_meetSearchView) {
        _meetSearchView = [[XMMeetSearchView alloc] initWithFrame:self.view.bounds];
        _meetSearchView.delegate = self;
    }
    return _meetSearchView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
